package com.yh.homestay.controller;

import com.yh.homestay.aop.SystemLog;
import com.yh.homestay.pojo.CapitalItem;
import com.yh.homestay.service.CapitalItemService;
import com.yh.homestay.common.HomeStayResult;
import com.yh.homestay.common.ItemEditResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName CapitalItemController
 * @Description 商品Controller
 * @Date 2020/1/13 15:04
 */
@RestController
@Api(description = "商品管理")
@RequestMapping(value = "/item")
public class CapitalItemController {
    @Autowired
    private CapitalItemService capitalItemService;

    /**
     * @param page
     * @param limit
     * @param itemName
     * @Date: 2020/1/13 15:05
     * @Description: 商品展示或者模糊查询并展示
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @SystemLog(methods = "商品展示", module = "商品管理")
    @ApiOperation(value = "获取所有商品列表", notes = "获取所有商品信息或者模糊查询")
    public HomeStayResult findCapitalItemAll(Integer page, Integer limit, String itemName) {
        return capitalItemService.findAll(page, limit, itemName);
    }

    /**
     * @param capitalItem
     * @Date: 2020/1/13 15:24
     * @Description: 添加商品
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @SystemLog(methods = "添加商品", module = "商品管理")
    @ApiOperation(value = "添加商品", notes = "添加商品信息")
    public HomeStayResult addCapitalItem(CapitalItem capitalItem) {
        return capitalItemService.addCapitalItem(capitalItem);
    }

    /**
     * @param id
     * @Date: 2020/1/13 15:24
     * @Description: 回显商品信息
     * @return: com.yh.homestay.common.ItemEditResult
     */
    @RequestMapping(value = "/goEdit/{id}", method = RequestMethod.POST)
    @ApiOperation(value = "回显商品信息", notes = "根据id进行回显商品信息")
    public ItemEditResult goEditCapitalItem(@PathVariable(value = "id") Integer id) {
        return capitalItemService.findItemById(id);
    }

    /**
     * @param capitalItem
     * @Date: 2020/1/13 15:24
     * @Description: 修改商品
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @SystemLog(methods = "修改商品", module = "商品管理")
    @ApiOperation(value = "修改商品", notes = "修改商品信息")
    public HomeStayResult editCapitalItem(CapitalItem capitalItem) {
        return capitalItemService.editCapitalItem(capitalItem);
    }

    /**
     * @param itemId
     * @Date: 2020/1/13 15:25
     * @Description: 删除商品
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
    @SystemLog(methods = "删除商品", module = "商品管理")
    @ApiOperation(value = "删除商品", notes = "删除商品数据")
    public HomeStayResult delCapitalItem(@PathVariable(value = "id") Integer itemId) {
        return capitalItemService.delCapitalItem(itemId);
    }


    /**
     * @param ids
     * @Date: 2020/1/13 15:25
     * @Description: 批量删除商品
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/deleteBatch", method = RequestMethod.POST)
    @SystemLog(methods = "删除多个商品", module = "商品管理")
    @ApiOperation(value = "批量删除商品", notes = "批量删除商品信息")
    public HomeStayResult batchDelCapitalItem(@RequestParam List<Integer> ids) {
        return capitalItemService.batchDelCapitalItem(ids);
    }

}
